package com.group4.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.group4.order.entity.Order;
import com.group4.order.mapper.OrderMapper;
import com.group4.order.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.group4.order.util.OrderUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author cloud
 * @since 2022-03-10
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    /**
     * 添加订单
     * @param order
     */
    @Override
    public void addOrder(Order order) {
//        order.setId("3");
        order.setOrderNo(OrderUtil.OrderUtils.getOrderCode());
//        order.setCourseId("1");
//        order.setIsDeleted(1);
//        order.setGmtCreate(new Date());
//        order.setGmtModified(new Date());
        orderMapper.insert(order);
    }

    /**
     * 根据订单编号查询订单
     * @param id
     * @return
     */
    @Override
    public Order findOrderById(String id) {

        return orderMapper.selectById(id);
    }

    /**
     * 修改订单
     * @param order
     * @param
     */
    @Override
    public void updateOrder(Order order) {
        orderMapper.updateById(order);
    }

    /**
     * 根据订单id判断是否支付成功
     * @param id
     * @return
     */
    @Override
    public Integer findByIdPay(String id) {
         Order order = orderMapper.selectById(id);
         return order.getStatus();
//         if(order.getStatus()==0){
//             //表示订单未支付,重定向到页面支付界面
//         }else{
//             //订单支付成功,跳转到视频播放页面
//
//         }

    }

    /**
     * 根据id删除订单
     * @param id
     */
    @Override
    public void deleteById(String id) {
        orderMapper.deleteById(id);
    }

    /**
     * 查询所有订单
     * @return
     */
    @Override
    public List<Order> getAll() {
        QueryWrapper<Order> queryWrapper=new QueryWrapper();
        return orderMapper.selectList(queryWrapper);
    }
}
